<template>
	<view class="add_box">
		<view class="infoItem wp entry dpflxrjb card ">
			<text class="iTitle">门店名称：</text>
			<picker class="iContent" :value="index" :range="list" :range-key="'shopName'" @change="changeShop">
				<text>{{ list[index].shopName }}</text>
				<view class="downArrow frt"></view>
			</picker>
		</view>


		<button class="btn_box5" @click="confirm">确认</button>

	</view>
</template>

<script>
	import request from "@/api/index.js";

	export default {
		data() {
			return {
				authorization: '',
				list: [],
				index: 0,
				uid:''
			}
		},

		onLoad(options) {
			var authorization = options.authorization;
			var uid = options.uid;
			var name_list = [];
			var id_list = [];

			this.authorization = authorization;
			this.uid = uid;
			
            console.log("uid="+uid);
			console.log("authorization="+authorization);
			request.loginToGetList(authorization, res => {
				if (res.data.code == 0) {
					var list = res.data.data;

					list.forEach(function(val) {
						if (val.isManager) {
							val.shopName = val.shopName + '【店长】';
						} else {
							val.shopName = val.shopName + '【员工】';
						}
					})

					this.list = list;
				} else {
					uni.showToast({
						title: res.msg,
						icon: 'none'
					})
				}
				// uni.reLaunch({
				// 	url: '/pages/index/index'
				// })
			})
		},

		methods: {
			changeShop: function(e) {
				this.index = e.detail.value;
			},

			confirm: function() {
				var list = this.list;
				var index = this.index;
				var authorization = this.authorization;
				var shop_id = list[index].id;
				var shop_name = list[index].shopName;
					
				uni.setStorageSync('shop_id', shop_id);
				uni.setStorageSync('shop_name', shop_name);
				uni.setStorageSync('authorization', authorization);
				const jyJPush = uni.requireNativePlugin('JY-JPushThird');
				jyJPush.setJYJPushAlias({
					userAlias: "STORE_PC_"+this.uid}, result=> {
					//  设置成功或者失败，都会通过这个result回调返回数据；数据格式保持极光返回的安卓/iOS数据一致
					//  注：若没有返回任何数据，考虑是否初始化完成
				    console.log(JSON.stringify(result));
				});
				uni.reLaunch({
					url: '/pages/index/index'
				})
			},
		}
	}
</script>

<style src="../../static/css/app.css"></style>
<style>

</style>
